import 'package:enterprise_v6_app/generated/json/base/json_convert_content.dart';
import 'package:enterprise_v6_app/app/data/entities/common/risk_tree_entity.dart';

RiskTreeEntity $RiskTreeEntityFromJson(Map<String, dynamic> json) {
  final RiskTreeEntity riskTreeEntity = RiskTreeEntity();
  final List<RiskTreeEntity>? children = (json['children'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<RiskTreeEntity>(e) as RiskTreeEntity).toList();
  if (children != null) {
    riskTreeEntity.children = children;
  }
  final String? currentRiskLevel = jsonConvert.convert<String>(json['currentRiskLevel']);
  if (currentRiskLevel != null) {
    riskTreeEntity.currentRiskLevel = currentRiskLevel;
  }
  final String? dataSrc = jsonConvert.convert<String>(json['dataSrc']);
  if (dataSrc != null) {
    riskTreeEntity.dataSrc = dataSrc;
  }
  final String? hazardDep = jsonConvert.convert<String>(json['hazardDep']);
  if (hazardDep != null) {
    riskTreeEntity.hazardDep = hazardDep;
  }
  final String? hazardDepId = jsonConvert.convert<String>(json['hazardDepId']);
  if (hazardDepId != null) {
    riskTreeEntity.hazardDepId = hazardDepId;
  }
  final String? hazardDistinguishPersonId = jsonConvert.convert<String>(json['hazardDistinguishPersonId']);
  if (hazardDistinguishPersonId != null) {
    riskTreeEntity.hazardDistinguishPersonId = hazardDistinguishPersonId;
  }
  final String? hazardLiablePerson = jsonConvert.convert<String>(json['hazardLiablePerson']);
  if (hazardLiablePerson != null) {
    riskTreeEntity.hazardLiablePerson = hazardLiablePerson;
  }
  final String? hazardLiablePersonId = jsonConvert.convert<String>(json['hazardLiablePersonId']);
  if (hazardLiablePersonId != null) {
    riskTreeEntity.hazardLiablePersonId = hazardLiablePersonId;
  }
  final String? id = jsonConvert.convert<String>(json['id']);
  if (id != null) {
    riskTreeEntity.id = id;
  }
  final String? initialRiskLevel = jsonConvert.convert<String>(json['initialRiskLevel']);
  if (initialRiskLevel != null) {
    riskTreeEntity.initialRiskLevel = initialRiskLevel;
  }
  final int? level = jsonConvert.convert<int>(json['level']);
  if (level != null) {
    riskTreeEntity.level = level;
  }
  final String? name = jsonConvert.convert<String>(json['name']);
  if (name != null) {
    riskTreeEntity.name = name;
  }
  final String? parentId = jsonConvert.convert<String>(json['parentId']);
  if (parentId != null) {
    riskTreeEntity.parentId = parentId;
  }
  final int? taskCount = jsonConvert.convert<int>(json['taskCount']);
  if (taskCount != null) {
    riskTreeEntity.taskCount = taskCount;
  }
  final bool? isExpand = jsonConvert.convert<bool>(json['isExpand']);
  if (isExpand != null) {
    riskTreeEntity.isExpand = isExpand;
  }
  final String? path = jsonConvert.convert<String>(json['path']);
  if (path != null) {
    riskTreeEntity.path = path;
  }
  return riskTreeEntity;
}

Map<String, dynamic> $RiskTreeEntityToJson(RiskTreeEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['children'] = entity.children?.map((v) => v.toJson()).toList();
  data['currentRiskLevel'] = entity.currentRiskLevel;
  data['dataSrc'] = entity.dataSrc;
  data['hazardDep'] = entity.hazardDep;
  data['hazardDepId'] = entity.hazardDepId;
  data['hazardDistinguishPersonId'] = entity.hazardDistinguishPersonId;
  data['hazardLiablePerson'] = entity.hazardLiablePerson;
  data['hazardLiablePersonId'] = entity.hazardLiablePersonId;
  data['id'] = entity.id;
  data['initialRiskLevel'] = entity.initialRiskLevel;
  data['level'] = entity.level;
  data['name'] = entity.name;
  data['parentId'] = entity.parentId;
  data['taskCount'] = entity.taskCount;
  data['isExpand'] = entity.isExpand;
  data['path'] = entity.path;
  return data;
}

extension RiskTreeEntityExtension on RiskTreeEntity {
  RiskTreeEntity copyWith({
    List<RiskTreeEntity>? children,
    String? currentRiskLevel,
    String? dataSrc,
    String? hazardDep,
    String? hazardDepId,
    String? hazardDistinguishPersonId,
    String? hazardLiablePerson,
    String? hazardLiablePersonId,
    String? id,
    String? initialRiskLevel,
    int? level,
    String? name,
    String? parentId,
    int? taskCount,
    bool? isExpand,
    String? path,
  }) {
    return RiskTreeEntity()
      ..children = children ?? this.children
      ..currentRiskLevel = currentRiskLevel ?? this.currentRiskLevel
      ..dataSrc = dataSrc ?? this.dataSrc
      ..hazardDep = hazardDep ?? this.hazardDep
      ..hazardDepId = hazardDepId ?? this.hazardDepId
      ..hazardDistinguishPersonId = hazardDistinguishPersonId ?? this.hazardDistinguishPersonId
      ..hazardLiablePerson = hazardLiablePerson ?? this.hazardLiablePerson
      ..hazardLiablePersonId = hazardLiablePersonId ?? this.hazardLiablePersonId
      ..id = id ?? this.id
      ..initialRiskLevel = initialRiskLevel ?? this.initialRiskLevel
      ..level = level ?? this.level
      ..name = name ?? this.name
      ..parentId = parentId ?? this.parentId
      ..taskCount = taskCount ?? this.taskCount
      ..isExpand = isExpand ?? this.isExpand
      ..path = path ?? this.path;
  }
}
